package com.eastfair.certificate.enumeration;

import com.eastfair.annotation.base.BaseEnum;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Getter;

import java.util.stream.Stream;

/**
 * <p>
 * 实体注释中生成的类型枚举
 * 动态表单
 * </p>
 *
 * @author ligang
 * @date 2023-05-17
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "FormFieldFieldTypeAttributeEnum", description = "字段类型属性:#{DICT:字典;API:api;OTHER:自定义;-枚举")
public enum FormFieldFieldTypeAttributeEnum implements BaseEnum {

    /**
     * DICT="字典"
     */
    DICT("字典"),
    /**
     * API="api"
     */
    API("api"),
    /**
     * OTHER="自定义"
     */
    OTHER("自定义"),
    ;

    @ApiModelProperty(value = "描述")
    private String desc;


    /**
     * 根据当前枚举的name匹配
     */
    public static FormFieldFieldTypeAttributeEnum match(String val, FormFieldFieldTypeAttributeEnum def) {
        return Stream.of(values()).parallel().filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static FormFieldFieldTypeAttributeEnum get(String val) {
        return match(val, null);
    }

    public boolean eq(FormFieldFieldTypeAttributeEnum val) {
        return val != null && eq(val.name());
    }

    @Override
    @ApiModelProperty(value = "编码", allowableValues = "DICT,API,OTHER", example = "DICT")
    public String getCode() {
        return this.name();
    }

}
